package com.cos.hospital.init;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.media.SoundPool;
import android.net.Uri;
import android.os.Bundle;
import android.os.Vibrator;
import android.support.multidex.MultiDexApplication;

import com.blankj.utilcode.util.Utils;
import com.cos.hospital.R;
import com.cos.hospital.code.Code;
import com.cos.hospital.model.UHttp;
import com.cos.hospital.model.bean.ErrorBean;
import com.cos.hospital.model.bean.PatientListBean;
import com.cos.hospital.model.bean.ResultBean;
import com.cos.hospital.model.connector.HttpMsgListener;
import com.cos.hospital.model.event.CureListUpdateEvent;
import com.cos.hospital.model.retrofit.HostWrapper;
import com.cos.hospital.model.retrofit.MyObserver;
import com.cos.hospital.model.retrofit.RequestServes;
import com.cos.hospital.tool.SPUtil;
import com.cos.hospital.tool.UDate;
import com.cos.hospital.tool.ULog;
import com.cos.hospital.tool.USP;
import com.cos.hospital.tool.UToast;
import com.cos.hospital.tool.UTxt;
import com.google.gson.JsonObject;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechUtility;
import com.jude.utils.JActivityManager;
import com.jude.utils.JUtils;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import me.jessyan.autosize.utils.LogUtils;

/**
 * @Description: <p>
 * @Author: Kosmos
 * @Date: 2018年09月08日 16:25
 * @Email: KosmoSakura@foxmail.com
 */
public class App extends MultiDexApplication {
    public static App instances;

    public static App getInstance() {
        return instances;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        instances = this;
        USP.instance().init(this, "Hospital");
        Utils.init(this);
        initLog();
        initJUtils();
        initSpeech();

        registerActivityLifecycle();
    }

    private void initSpeech() {
        SpeechUtility.createUtility(this, SpeechConstant.APPID + "=57a42f07");
    }

    private void initJUtils() {
        JUtils.initialize(this); // 初始化工具库
        registerActivityLifecycleCallbacks(JActivityManager.getActivityLifecycleCallbacks());
    }

    private void initLog() {
        ULog.init(this)
                .setLogSwitch(Code.DebugState)
                .setConsoleSwitch(Code.DebugState)
                .setGlobalTag("Sakura")
                .setLogHeadSwitch(true)
                .setLog2FileSwitch(false)
                .setDir("")
                .setFilePrefix("Sakura")
                .setBorderSwitch(true)
                .setSingleTagSwitch(true)
                .setConsoleFilter(ULog.V)
                .setFileFilter(ULog.V)
                .setStackDeep(1)// log 栈深度，默认为 1
                .setStackOffset(0);
    }

    private void registerActivityLifecycle() {
        registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
                LogUtils.e("界面==》》" + activity.getLocalClassName());
            }

            @Override
            public void onActivityStarted(Activity activity) {

            }

            @Override
            public void onActivityResumed(Activity activity) {

            }

            @Override
            public void onActivityPaused(Activity activity) {

            }

            @Override
            public void onActivityStopped(Activity activity) {

            }

            @Override
            public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

            }

            @Override
            public void onActivityDestroyed(Activity activity) {
            }
        });
    }
}
